package com.magic.gre.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;

import com.magic.gre.R;
import com.magic.gre.base.activity.BaseMVPActivity;
import com.magic.gre.mvp.contract.SmsCodeContract;
import com.magic.gre.mvp.presenter.SmsCodePresenterImpl;
import com.noname.lib_base_java.util.ToastUtil;
import com.noname.lib_base_java.util.ValidateUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Author: Lmoumou
 * Date: 2019-01-31 16:59
 * 文件名: BindPhoneActivity
 * 描述:
 */
public class BindPhoneActivity extends BaseMVPActivity<SmsCodePresenterImpl> implements SmsCodeContract.View {

    public static void startThis(Context context, String openId) {
        Intent intent = new Intent(context.getApplicationContext(), BindPhoneActivity.class);
        intent.putExtra("openId", openId);
        context.startActivity(intent);
    }

    @BindView(R.id.phone_edt)
    EditText phoneEdt;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_bind_phone;
    }

    @Override
    protected SmsCodePresenterImpl creatPresenter() {
        return new SmsCodePresenterImpl(this);
    }

    @Override
    protected void netOverride() {

    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        super.initView(savedInstanceState);
    }

    @OnClick(value = {R.id.code_bt})
    protected void onClick(View view) {
        switch (view.getId()) {
            case R.id.code_bt:

                String phoneStr = String.valueOf(phoneEdt.getText());

                if (!ValidateUtil.Mobile(phoneStr)) {
                    ToastUtil.getInstance().showNormal(this, "请输入正确手机号");
                    return;
                }
                mPresenter.pSmsCode(phoneStr, 0);
                break;
        }
    }

    @Override
    public void vSmsCode(String code) {
        ToastUtil.getInstance().showNormal(this, code);
        CodeActivity.startThis(this,
                CodeActivity.BIND_PHONE,
                String.valueOf(phoneEdt.getText()),
                code,
                getIntent().getStringExtra("openId"));
    }
}
